<?php
session_start();
/**
 * ===== groups
 * root = 1
 * ====/ groups
 */
if(
	(!empty($_SESSION["Auth"]["User"]["group_id"])) 
		&& 
	(
		(($_SESSION["Auth"]["User"]["group_id"] == 1) || ($_SESSION["Auth"]["User"]["group_id"] == 3))
	)
) {
?>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Медиа Мениджър</title>
</head>
<body>
<a href="#" onClick="javascript:window.close()" class="menu">затвори този прозорец</a><br />
<br />
<?php

//--------------------------------------- PATH OF DIR
@ $url_dirMain = $_GET['dir'];
@ $url_dirId = $_GET['id'];
$final_dir = '';

if($url_dirMain == 'categories') {
	$final_dir = '/categories/'.$url_dirId.'/';
} else if($url_dirMain == 'locations') {
	$final_dir = '/locations/'.$url_dirId.'/';
} else {
	$final_dir = '/';
}
//--------------------------------------/ PATH OF DIR

$media_dir = '../../files/site_data/tinymce_uploads'.$final_dir;
	
if(file_exists(realpath($media_dir)))
{
	if($handle = opendir($media_dir)) 
	{
			echo '<table border="1">';
			echo '<tr>';
				echo '<th>Файл #</th>';
				echo '<th>Име на файл</th>';
				echo '<th>Преглед</th>';
			echo '</tr>';
		    $i=0;
			while (false !== ($file = readdir($handle))) {
				if($file=='.' || $file=='..' || $file=='index.html') continue;
				
				echo '<tr>';
				echo '<td>'.++$i.'</td>';
				echo '<td>'.htmlspecialchars($file).'</td>';
				echo '<td><a target="_blank" href="'.$media_dir.$file.'">Преглед</a></td>';
				echo '</tr>';
		    }
			echo '<table>';
			
		    closedir($handle);
	}
} else {
	echo '<p>Папката не съществува. Моля, качете първо един или повече файлове.</p>';
}
?>
</body>
</html>
<?php
} else {
echo 'Login first...';
}
?>